package com.ttb.schedule;

import com.ttb.blocksms.BlockService;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class ScheduleHandler {
	final public static String ONE_TIME = "onetime";

	public void SetAlarm(Context context)
    {
        AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, BlockService.class);
        intent.setAction("com.ttb.smshelper.SCHEDULE_SMS");
        //intent.putExtra(ONE_TIME, Boolean.FALSE);
        //intent.putExtra("ID",String.valueOf(System.currentTimeMillis()));
        //intent.putExtra("ID", "sadasdasdasdasd");
  		Log.d("Time set : ", String.valueOf(System.currentTimeMillis()));
        PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
        //After after 30 seconds
        am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 5 , pi); 
    }

    public void CancelAlarm(Context context)
    {
        Intent intent = new Intent(context, BlockService.class);
        intent.setAction("com.ttb.smshelper.SCHEDULE_SMS");
        PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.cancel(sender);
    }

}
